<template>
    <section class="coupon-box pdlr15">
      <van-radio-group v-model="radio">
        <div class="coupon bgcFFF mt10" clickable  @click="handleChooseCoupon(item,$event)" v-for="(item,index) in couponData" :key="index">
          <div class="coupon-l text-c" :class="item.use == 1 ? 'bgImgUse' : 'bgImgUnusable'">
            <p>￥<strong>{{item.sum}}</strong></p>
            <p>{{item.condition}}</p>
          </div>
          <div class="coupon-r flr pr">
            <van-row class="pr">
              <van-col span="20">
                <p class="clamp2">{{item.name}}</p>
                <p>{{item.validity}}
                  <span class="flr" @click="handleShowDetail(index,$event)">
                    说明
                    <i class="iconfont icondown" :class="'icondown' + index"></i>
                  </span>
                </p>
              </van-col>
              <van-col span="4">
                <span v-if="item.checked == 1">
                  <van-radio :name="item.id"/>
                </span>
              </van-col>
            </van-row>
            <!--已过期-->
            <img v-if="item.past_due == 1" class="icon_coupon" src="../assets/img/icon_coupon_past_due.png" alt="已过期">
            <!--已使用-->
            <img v-if="item.used == 1" class="icon_coupon" src="../assets/img/icon_coupon_used.png" alt="已使用">
          </div>
          <div class="detail-msg line-top fs12 color7A7B82" :id="'detail' + index">
            {{item.condition}}
          </div>
        </div>
      </van-radio-group>
    </section>
</template>

<script type="text/ecmascript-6">
  export default {
    data() {
      return {
        radio:'',
        id: '',
      }
    },
    props:['couponData'],
    methods: {
      handleChooseCoupon(item,e){
        e.stopPropagation()
        if(this.radio == '') {
          this.radio = item.id
          this.id = item.id
          this.$emit('send-coupon',{item:item})
        } else {
          if(item.id === this.id) {
            this.radio = ''
            this.$emit('send-coupon',{item:''})
          } else {
            this.radio = item.id
            this.id = item.id
            this.$emit('send-coupon',{item:item})
          }
        }

//        this.radio = item.id
//        this.$emit('send-coupon',{item:item})
      },
      handleShowDetail(index,e){
        e.stopPropagation()
        if($('.icondown' + index).hasClass('icondown')){
          $('.icondown' + index).removeClass('icondown').addClass('iconup')
          $(e.target).parents('.coupon').children('.detail-msg').slideDown()
        }else{
          $('.icondown' + index).removeClass('iconup').addClass('icondown')
          $(e.target).parents('.coupon').children('.detail-msg').slideUp()
        }
      },
    },
  }
</script>

<style scoped lang="scss">
  @import '../assets/css/base';


  .coupon-box{
    .coupon{
      height: auto;
      width: 100%;
      font-size: 0;
      border-radius: 4px;

      .bgImgUse{
        background: url("../assets/img/coupon_use_bg.png") no-repeat;
        background-size: 100% 100%;
      }

      .bgImgUnusable{
        background: url("../assets/img/coupon_unusable_bg.png") no-repeat;
        background-size: 100% 100%;
      }

      .coupon-l{
        display: inline-block;
        width:100px;
        height: 90px;
        color: #fff;
        font-size: 12px;

        p:nth-child(1){
          font-size: 14px;
          padding-top: 15px;

          strong{
            font-size: 32px;
          }
        }
      }

      .coupon-r{
        display: inline-block;
        height: 90px;
        width: calc(100% - 100px);
        padding:12px 15px 12px 12px;
        box-sizing: border-box;
        font-size: 14px;
        overflow: hidden;

        .van-row{
          height: 100%;

          .van-col:nth-child(1) {

            p:nth-child(2){
              position: absolute;
              bottom:0;
              left:0;
              width: 100%;
              color: #7A7B82;
              font-size: 11px;

              span{
                position: relative;
                top: -1px;
                left: 0px;
                z-index:20;

                i{
                  position: relative;
                  top: 2px;
                  left:0;
                  font-size: 14px;
                  transition: all 0.8s ease-in-out;
                }
              }
            }
          }

          .van-col:nth-child(2){
            span{
              display: flex;
              justify-content: flex-end;
              align-items: center;
              height: 66px;
              width: 100%;
            }
          }
        }

        .icon_coupon{
          position: absolute;
          right: 5px;
          top: 30px;
          width: 74px;
          height: 74px;
        }
      }

      .detail-msg{
        display: none;
        width:100%;
        height: auto;
        padding:12px 15px;
        box-sizing: border-box;
        border-radius: 4px;
      }
    }
  }
</style>
